var miguanPlugin = function () {
	var _self = this;
	var siteurl = "http://adzjz.ekuapi.com";
	var keywordData = [];


	this.run = function () {
		var miguan_plugin_close = _self.cookie.get('tuibaozhushou_close');
		if (!miguan_plugin_close || miguan_plugin_close == 0) {
			if (_self.$c('tbzs_tbzs') != "undefined")
				_self.$c('tbzs_tbzs').style.display = "block";
		}
		_self.$c("tuibaozhushou_close").onclick = function () {
			var w = 120 + 10;
			//_self.$c("tbzs_tbzs").style.right='-'+w+'px';
			if (_self.$c('tbzs_tbzs') != "undefined")
				_self.$c("tbzs_tbzs").style.display = 'none';
			_self.cookie.add('miguan_plugin_close', 1);
		}
		_self.$c("tbzs_tbzs_hyz").onclick = function () {
			var url = window.location.href;
			var title = document.title;
			var time = parseInt(10 * Math.random());
			//			$.get(siteurl+"/chrome/index?type=main&url="+url+"",function(jsondata){
			//				jsondata=strToJson(jsondata);
			//				if(jsondata.state>0){
			//					_self.$c("tbzs_tbzs_ul").innerHTML=jsondata.data;
			//				}else{
			//					//alert(jsondata.data)
			//				}
			//			})	
		};
	};
	this.$c = function (classname) {
		var classElements = [],
			allElements = document.getElementsByTagName('*');
		for (var i = 0; i < allElements.length; i++) {
			if (allElements[i].className == classname) {
				classElements[classElements.length] = allElements[i];
				return allElements[i];
			}
		}
		return false;
	};
	this.cookie = {
		"add": function (name, value, expiresHours) {
			var cookieString = name + "=" + escape(value);
			//判断是否设置过期时间 
			if (expiresHours > 0) {
				var date = new Date();
				date.setTime(date.getTime + expiresHours * 3600 * 1000);
				cookieString = cookieString + "; expires=" + date.toGMTString();
			}
			document.cookie = cookieString;
		},
		"get": function (name) {
			var strCookie = document.cookie;
			var arrCookie = strCookie.split("; ");
			for (var i = 0; i < arrCookie.length; i++) {
				var arr = arrCookie[i].split("=");
				if (arr[0] == name) return arr[1];
			}
			return "";
		},
		"delete": function (name) {
			var date = new Date();
			date.setTime(date.getTime() - 10000);
			document.cookie = name + "=v; expires=" + date.toGMTString();
		}

	};
	this.postData = function () {
		var title = $("title").text();
		var url = window.location.href;
		$.get(siteurl + "/chrome/index", {
			"title": title,
			"url": url
		}, function (result) {
			try {
				var jsondata = strToJson(result);
				var state = jsondata.state;
				if (state > 0) {
					$("body").append(jsondata.data);
					if ($("#zhitui_plugin_mode").val() == 0) {
						$miguanplugin.run();
					}
				}
			} catch (e) {
				//alert(e.message);
				$miguanplugin.run();
			}

		})
	};
};

var $miguanplugin = new miguanPlugin();
$miguanplugin.postData();